package com.starview.star.compiler.wff;

import java.util.ArrayList;
import java.util.List;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Abstract;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class WffTupleBody implements WffBuildOp
{
  final WffBuildOp els[];

  public WffTupleBody(WffBuildOp els[])
  {
    this.els = els;
  }

  @Override
  public IAbstract build(IAbstract[] env, Location loc, WffEngine engine)
  {
    List<IAbstract> oArgs = new ArrayList<IAbstract>();

    for (int ix = 0; ix < els.length; ix++)
      oArgs.add(els[ix].build(env, loc, engine));

    return Abstract.tupleTerm(loc, oArgs);
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append("(");
    String sep = "";

    for (WffBuildOp op : els) {
      disp.append(sep);
      sep = ", ";
      op.prettyPrint(disp);
    }
    disp.append(")");
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }

}
